<link rel="stylesheet" href="/js/intlTelInput/css/intlTelInput.css">
<script src="/js/intlTelInput/js/intlTelInput.js"></script>
<!--    <ul class="register_step">
        <li><span class="move">1</span>用户注册</li>
        <li><span <?php /*if($step ==2){ */?>class="move"<?php /*} */?>>2</span>交易密码</li>
        <li><span <?php /*if($step ==3){ */?>class="move"<?php /*} */?>>3</span>实名认证</li>
        <li><span <?php /*if($step ==4){ */?>class="move"<?php /*} */?>>4</span>注册成功</li>
    </ul>-->
    <div class="login register">
        <!-- <h1>注册</h1> -->
        <?php if(!$success){ ?>
        <form id="form_1" action="" class="form">
            <div class="form-group">
                <p>您的手机号</p>

                <div class="input-group ismobile">
                    <input name="input_moble_pre" class="texts" type="text" style="display: none;">
                    <input name="input_moble" style="padding-left:50px" class="fromInt mobile_int" type="tel"
                           maxlength="11" placeholder="请输入手机号码">
                </div>
            </div>
            <div class="form-group">
                <p>密码</p>
                <div class="input-group"><input name="password" type="password" class="fromInt" placeholder="请输入您的密码">
                </div>
            </div>
            <div class="form-group">
                <p>确认密码</p>

                <div class="input-group"><input name="confirm_password" type="password" class="fromInt" placeholder="请再次确认密码">
                </div>
            </div>
            <div class="form-group">
                <p>验证码</p>
                <div class="input-group"><input name="verify" type="tel" class="fromInt" maxlength="6" placeholder="请输入验证码"></div>
                <div id="reg_moble" class="code"><a onclick="moble_reg('msm')">短信验证码</a></div>
            </div>
<!--            <div class="form-group">
                <p>邀请码</p>

                <div class="input-group"><input name="invit" type="tel" class="fromInt" placeholder="请输入邀请码"></div>
            </div>-->
            <div class="form-check">
                <input name="regweb" type="checkbox" class="left">
                <span class="left">注册即视为同意 <a id="regweb" href="javascript:">用户注册协议</a></span>
            </div>
            <button type="button" onclick="reg_up()">注册</button>
        </form>
        <?php }elseif($success==1){ ?>
        <form id="form_4" action="" class="form">
            <div class="reg_success">
                <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                <span>注册成功</span>
            </div>
<!--            <div class="form-group s_group">
                <p><i>手机号：</i><?/*= $moble */?></p>
            </div>-->
            <button type="submit" onclick="go_trade()">登录</button>
        </form>
<!--        <footer>
            <p>已註冊？<a href="/login.html">登录</a></p>
        </footer>-->
        <?php } ?>
    </div>
    <script>

        $("input[name='input_moble_pre']").intlTelInput({
            autoHideDialCode: false,
            defaultCountry: "cn",
            nationalMode: false,
            preferredCountries: ['cn', 'us', 'hk', 'tw', 'mo']
        });


        function moble_reg(type) {
            var moble = $("input[name='input_moble']").val();
            var mobles = $("input[name='input_moble_pre']").val();
            if (moble == "" || moble == null) {
                $('input[name="input_moble"]').tooltip({
                    title: "请输入手机号码",
                    trigger: 'blur'
                }).tooltip('show');
                return false;
            }
            $.post("/sms.html", {
                moble: moble,
                mobles: mobles,
                type: type
            }, function (data) {
                if (data.errCode == 0) {
                    $("input[name='verify']").focus();
                    $("input[name='input_moble']").attr("disabled", "disabled");
                    $("input[name='input_moble_pre']").attr("disabled", "disabled");
                    var obj = $('#reg_moble');
                    var wait = 60;
                    var interval = setInterval(function () {
                        obj.html(wait);
                        wait--;
                        if (wait < 0) {
                            clearInterval(interval);
                            obj.html('<a onclick="moble_reg('+"'msm'"+')">重新发送</a>');
                        }
                    }, 1000);
                }else {
                    layer.msg(data.errMsg, {icon: 2});
                }
            })
        }

        function reg_up() {
            var moble = $("input[name='input_moble']").val();
            var mobles = $("input[name='input_moble_pre']").val();
            var moble_verify = $("input[name='verify']").val();
            var password = $("input[name='password']").val();
            var confirm_password = $("input[name='confirm_password']").val();

            if (moble == "" || moble == null) {
                $('input[name="input_moble"]').tooltip({
                    title: "请输入手机号码",
                    trigger: 'blur'
                }).tooltip('show');
                return false;
            }
            var regx =/^(?!([a-zA-Z]+|\d+)$)[a-zA-Z\d]{6,16}$/;
            if (password == "" || password == null || !password.match(regx)) {
                $('input[name="password"]').tooltip({
                    title: "密码6~16位，且必须包含字母和数字",
                    trigger: 'blur'
                }).tooltip('show');
                return false;
            }
            console.log(confirm_password);
            if(!confirm_password || confirm_password != password){
                $('input[name="confirm_password"]').tooltip({
                    title: "2次密码输入不一致",
                    trigger: 'blur'
                }).tooltip('show');
                return false;
            }
            if (moble_verify == "" || moble_verify == null) {
                $('input[name="verify"]').tooltip({
                    title: "请输入验证码",
                    trigger: 'blur'
                }).tooltip('show');
                return false;
            }
            if (!$("input[name='regweb']").is(':checked')) {
                $('#regweb').tooltip({
                    title: "请勾选用户注册协议",
                    trigger: 'blur'
                }).tooltip('show');
                return false;
            }


            $.post("register.html", {
                moble: moble,
                mobles: mobles,
                moble_verify: moble_verify,
                password: password
            }, function (data) {
                if (data.errCode == 0) {
                    window.location = '/register.html?success=1&moble=' + moble;
                } else {
                    layer.msg(data.errMsg, {icon: 2});
                }
            }, "json");
        }

        function go_trade() {
            window.location = '/login.html';
        }
    </script>